//
//  MessShowView.m
//  bus
//
//  Created by zhanshu on 15/6/8.
//  Copyright (c) 2015年 ygs. All rights reserved.
//

#import "MessShowView.h"
#import "Toast+UIView.h"
@implementation MessShowView

+ (MessShowView *)share{
    static MessShowView *messShowView = nil;
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        messShowView = [[MessShowView alloc] init];
    });
    return messShowView;
}
- (id)init {
    self = [super init];
    if (self) {
        _isShow = YES;
    }
    return self;
}

- (void)showWithMess:(NSString *)mess{
//    if (self.isShow) {
//        _isShow = NO;
//        UIWindow *window = [UIApplication sharedApplication].delegate.window;
//        [window makeToast:mess duration:1.0 position:@"center"];
//        [self performSelector:@selector(delayMethod) withObject:nil afterDelay:1.4];
//    }
    if (mess.length == 0) {
        return;
    }else {
        //高度宽度自适应
        UILabel *notivL = [[UILabel alloc]init];
        notivL.text = mess;
        notivL.numberOfLines = 0;
        UIFont *font = [UIFont systemFontOfSize:12];
        notivL.font = font;
        notivL.textAlignment = NSTextAlignmentCenter;
        notivL.textColor = [UIColor whiteColor];
        CGSize constraint = CGSizeMake(280, 20000.0f);
        NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,nil];
        CGSize size = [mess boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin attributes:tdic context:nil].size;
        
        UIWindow *window = [UIApplication sharedApplication].delegate.window;
        UIView *noticView = [[UIView alloc]init];
        noticView.frame = CGRectMake((ScreenWidth-size.width-20)/2, (ScreenHeight-size.height-20)/2, size.width+20, size.height+20);
        noticView.backgroundColor = [UIColor blackColor];
        noticView.alpha = 0.8;
        noticView.layer.cornerRadius = 5.0;
        noticView.layer.masksToBounds = YES;
        [window addSubview:noticView];
        
        notivL.frame = CGRectMake(10, 10, size.width, size.height);
        [noticView addSubview:notivL];
        [UIView animateWithDuration:0.5 delay:1.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
            noticView.alpha=0;
        } completion:nil];
    }
}
-(void)showWithMess:(NSString *)mess login:(BOOL)islogin {
    if (mess.length == 0) {
        return;
    }else {
        //高度宽度自适应
        UILabel *notivL = [[UILabel alloc]init];
        notivL.text = mess;
        notivL.numberOfLines = 0;
        UIFont *font = [UIFont systemFontOfSize:12];
        notivL.font = font;
        notivL.textAlignment = NSTextAlignmentCenter;
        notivL.textColor = [UIColor whiteColor];
        CGSize constraint = CGSizeMake(280, 20000.0f);
        NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,nil];
        CGSize size = [mess boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin attributes:tdic context:nil].size;
        UIWindow *window = [UIApplication sharedApplication].delegate.window;
        UIView *noticView = [[UIView alloc]init];
        noticView.frame = CGRectMake((ScreenWidth-size.width-20)/2, (ScreenHeight-size.height-50)/2, size.width+20, size.height+50);
        noticView.backgroundColor = [UIColor blackColor];
        noticView.alpha = 0.8;
        noticView.layer.cornerRadius = 5.0;
        noticView.layer.masksToBounds = YES;
        [window addSubview:noticView];
        UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake((noticView.frame.size.width-20)/2, 10, 20, 20)];
        [noticView addSubview:imageV];
        if (islogin) {
            imageV.image = [UIImage imageNamed:@"duihao"];
        }else {
            imageV.image = [UIImage imageNamed:@"cha"];
        }
        notivL.frame = CGRectMake(10, 40, size.width, size.height);
        [noticView addSubview:notivL];
        [UIView animateWithDuration:0.5 delay:1.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
            noticView.alpha=0;
        } completion:nil];
    }
}

- (void)delayMethod {
    _isShow = YES;
}

@end
